package cn.superchart.module.dev.template.controller;
import cn.superchart.common.base.BaseController;
import cn.superchart.common.base.BaseResult;
import cn.superchart.module.dev.template.entity.ScTemp;
import cn.superchart.module.dev.template.param.*;
import cn.superchart.module.dev.template.service.ScTempService;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;


@RestController
@Validated
public class ScTempController extends BaseController<ScTempService> {

    @PostMapping("/sc/scTemp/add")
    public BaseResult<String> add(@RequestBody @Valid ScTempAddParam scTempAddParam) {
        service.add(scTempAddParam);
        return BaseResult.ok();
    }

    @PostMapping("/sc/scTemp/edit")
    public BaseResult<String> edit(@RequestBody @Valid ScTempEditParam scTempEditParam) {
        service.edit(scTempEditParam);
        return BaseResult.ok();
    }


    @PostMapping("/sc/scTemp/setContent")
    public BaseResult<String> setContent(@RequestBody @Valid ScTempContentParam scTempContentParam) {
        service.setContent(scTempContentParam);
        return BaseResult.ok();
    }
    @GetMapping("/sc/scTemp/getContent")
    public BaseResult<String> getContent(@Valid ScTempIdParam scTempIdParam) {
        String content = service.getContent(scTempIdParam.getId());
        return BaseResult.result(content);
    }

    @PostMapping("/sc/ScTemp/previewContent")
    public BaseResult<String> previewContent(@RequestBody @Valid  ScTempContentParam scTempContentParam) {
        String htmlStr = service.previewContent(scTempContentParam);
        return BaseResult.result(htmlStr);
    }


    @GetMapping("/sc/ScTemp/detail")
    public BaseResult<ScTemp> detail(@Valid ScTempIdParam scTempIdParam) {
        return BaseResult.result(service.detail(scTempIdParam));
    }

    @GetMapping("/sc/ScTemp/info")
    public BaseResult<ScTempDetailParam> info(@Valid ScTempIdParam scTempIdParam) {
        return BaseResult.result(service.info(scTempIdParam));
    }
}
